package com.bestvike.stone.spring.quartz.core;

import com.bestvike.stone.core.reflect.ReflectionUtils;
import org.quartz.spi.JobFactory;
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

/**
 * Created by 许崇雷 on 2018-08-27.
 */
public final class JobFactoryCustomizer implements SchedulerFactoryBeanCustomizer {
    /**
     * custom job factory
     */
    @Override
    public void customize(SchedulerFactoryBean schedulerFactoryBean) {
        JobFactory jobFactory = ReflectionUtils.getFieldValue(schedulerFactoryBean, "jobFactory");
        if (jobFactory == null || jobFactory instanceof DelegatingJobFactory)
            return;
        schedulerFactoryBean.setJobFactory(new DelegatingJobFactory(jobFactory));
    }
}
